package com.example.calendar.data.model

import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
import org.threeten.bp.LocalDateTime
import java.util.UUID

/**
 * Priority levels for tasks
 */
enum class TaskPriority {
    NONE,
    LOW,
    MEDIUM,
    HIGH
}

/**
 * Represents a task with all its properties
 */
@Parcelize
@Entity(tableName = "tasks")
data class Task(
    @PrimaryKey
    val id: String = UUID.randomUUID().toString(),
    val title: String,
    val description: String? = null,
    val dueDate: LocalDateTime? = null,
    val isCompleted: Boolean = false,
    val completedDate: LocalDateTime? = null,
    val priority: TaskPriority = TaskPriority.NONE,
    val reminderMinutes: List<Int> = emptyList(),
    val categoryId: String? = null,
    val color: Int? = null,
    val createdAt: LocalDateTime = LocalDateTime.now(),
    val updatedAt: LocalDateTime = LocalDateTime.now(),
    val isDeleted: Boolean = false
) : Parcelable {
    
    /**
     * Check if the task is overdue
     */
    fun isOverdue(): Boolean {
        return dueDate != null && 
                !isCompleted && 
                dueDate.isBefore(LocalDateTime.now())
    }
    
    /**
     * Check if the task is due today
     */
    fun isDueToday(): Boolean {
        if (dueDate == null) return false
        
        val today = LocalDateTime.now().toLocalDate()
        val taskDate = dueDate.toLocalDate()
        
        return taskDate.isEqual(today)
    }
    
    /**
     * Mark the task as completed
     */
    fun complete(): Task {
        return if (!isCompleted) {
            copy(
                isCompleted = true,
                completedDate = LocalDateTime.now(),
                updatedAt = LocalDateTime.now()
            )
        } else {
            this
        }
    }
    
    /**
     * Mark the task as incomplete
     */
    fun uncomplete(): Task {
        return if (isCompleted) {
            copy(
                isCompleted = false,
                completedDate = null,
                updatedAt = LocalDateTime.now()
            )
        } else {
            this
        }
    }
} 